package ${package};

<#if imports?exists>
	<#list imports as import>
import ${import};
	</#list>
</#if>

@Component
public class ${className} extends ParentSyncVerticle {

	private static final Logger logger = LoggerFactory.getLogger(${className}.class);

	@Resource(name = "${util.firstLower(service.simpleName)}")
	private ${service.simpleName} ${util.firstLower(service.simpleName)};

	protected void buildRouter() {
		router.get("/${util.firstLower(bean)}/list").handler(fiberHandler(this::list));
		router.get("/${util.firstLower(bean)}/list/json").handler(fiberHandler(this::listJson));
		router.get("/${util.firstLower(bean)}/view/:id").handler(fiberHandler(this::view));
		router.get("/${util.firstLower(bean)}/view/json/:id").handler(fiberHandler(this::viewJson));
		router.get("/${util.firstLower(bean)}/toEdit/:id").handler(fiberHandler(this::toEdit));
		router.get("/${util.firstLower(bean)}/save/json").handler(fiberHandler(this::listJson));
		router.get("/${util.firstLower(bean)}/save").handler(fiberHandler(this::view));
	}

	@Suspendable
	private void ftlDb(RoutingContext routingContext) {
		JDBCClient jdbcClient = DbUtil.getJdbcClient(vertx);
		try {
			List<JsonObject> jsonObjects = questionService.insertAndList(jdbcClient);
			routingContext.response()
				.putHeader("content-type", "application/json; charset=utf-8")
				.end(Json.encodePrettily(jsonObjects));
		} catch (Exception e) {
			logger.error("ftlDb", e);
			routingContext.response()
			.putHeader("content-type", "application/json; charset=utf-8")
			.end("error!!!!!!!!!!!!");
		}
	}

    @Suspendable
    private void ftlIndex(RoutingContext ctx) {
    	JDBCClient jdbcClient = DbUtil.getJdbcClient(vertx);
    	try {
    		List<JsonObject> jsonObjects = questionService.list(jdbcClient);
        	ctx.put("jsonObjects", jsonObjects);
        	engine.render(ctx, "/template/", "questionList.ftl", res -> {
        		if (res.succeeded()) {
        			ctx.response().end(res.result());
        		} else {
        			ctx.fail(res.cause());
        		}
        	});
        } catch (Exception e) {
        	e.printStackTrace();
        	logger.error("ftlIndex", e);
        	ctx.response()
        		.putHeader("content-type", "application/json; charset=utf-8")
        		.end("error!!!!!!!!!!!!");
        }
     }

}